/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import Entities.TblBranch;
import Entities.TblRoles;
import Entities.TblStaff;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@RequestScoped
public class StaffManagedBean extends TblStaff {

    /** Creates a new instance of StaffManagedBean */
    public StaffManagedBean() {
    }
    private List<TblStaff> all;
    private static TblStaff staffBean;

    public List<TblStaff> getAll() {
        try {
            return new BLL.StaffBLL().getAll();
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public String add() {
        try {
            this.staffBean.setStatus(true);
            new BLL.StaffBLL().add(this.staffBean);
            return "stafflist";
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return "null";
        }
    }

    public String update() throws Exception {
        if (new BLL.StaffBLL().update(this.staffBean)) {
            return "stafflist";
        } else {
            return "null";
        }
    }

    public String delete() throws Exception {
        if (new BLL.StaffBLL().delete(this.staffBean)) {
            return "stafflist";
        } else {
            return "null";
        }
    }
    
    public String branchNameById(int branchId){
        TblBranch objBranch=new BLL.BranchBLL().getById(branchId);
        return objBranch.getBranchName();
    }
    public String roleNameById(int roleId){
        TblRoles objRole=new BLL.RoleBLL().getById(roleId);
        return objRole.getRoleName();
    }
    public TblStaff getStaffBean() {
        return staffBean;
    }

    public void setStaffBean(TblStaff staffBean) {
        this.staffBean = staffBean;
    }
}
